<?php
/*******************************************
	Curl procedures
*******************************************/

// Avoid direct access
if(substr_count($_SERVER['PHP_SELF'], 'curl.php') > 0) {
	header("HTTP/1.0 404 Not Found");
	exit;
}


class Curl {

	function __construct() {
	
	}
	
	protected function init($cookie=null, $delete_cookie=true, $url=null) {
		
		if(is_null($cookie)) {
			$cookie = $_SERVER['DOCUMENT_ROOT']."/php/mobile/resources/cookies/cookie_".md5(time());
		}
		
		if($delete_cookie) {
			if(is_file($cookie)) {
				unlink($cookie);
			}			
		}
		
		$ch = curl_init($url);
		curl_setopt ($ch, CURLOPT_USERAGENT,"Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)");
		//curl_setopt ($ch, CURLOPT_USERAGENT,"Mozilla/5.0 (SymbianOS/9.2; U; Series60/3.1 NokiaXxx/1.0; Profile/MIDP-2.0 Configuration/CLDC-1.1) AppleWebKit/413 (KHTML, like Gecko) Safari/413");
		curl_setopt ($ch, CURLOPT_TIMEOUT,10);
		curl_setopt ($ch, CURLOPT_RETURNTRANSFER,1);
		//curl_setopt ($ch, CURLOPT_BINARYTRANSFER,1);
		curl_setopt ($ch,CURLOPT_FRESH_CONNECT,0);
		curl_setopt ($ch, CURLOPT_HEADER,0);
		curl_setopt ($ch, CURLOPT_FOLLOWLOCATION,true);
	    curl_setopt ($ch, CURLOPT_COOKIEJAR,$cookie);
	    curl_setopt ($ch, CURLOPT_COOKIEFILE,$cookie);
	    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
	    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
		curl_setopt ($ch, CURLOPT_AUTOREFERER,1);
		curl_setopt ($ch, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1);
		curl_setopt ($ch, CURLOPT_MAXREDIRS,5);		
		
		return $ch;
		
	}

}

?>